<!-- 楼层组件 -->
<template>
  <div class="floor">
    <div class="floor-title">{{floorTitle}}</div>
    <div class="floor-anomaly">
      <div class="floor-one">
        <img :src="floorData0.image" alt="左侧" width="100%" />
      </div>
      <div>
        <div class="floor-two">
          <img :src="floorData1.image" alt="右侧上" width="100%" />
        </div>
        <div>
          <img :src="floorData2.image" alt="右侧下" width="100%" />
        </div>
      </div>
    </div>
    <div class="floor-rule">
      <div v-for="(item, index) in floorData.slice(3)" :key="index">
        <img :src="item.image" alt="下方图片" width="100%" />
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      floorData0: {},
      floorData1: {},
      floorData2: {},
    };
  },
  // 接收传递的属性值
  props: ['floorData', 'floorTitle'],
  watch: {
    // 用watch对象好坚挺组件属性值的变化，如果在created里面获取，由于axios是异步获取到的数据，
    // 所以这个组件初始化时会获取不到image数据，所以这里使用watch进行监听获取
    floorData(data) {
      // 这里的函数不能用箭头函数，否则会出不来数据
      // data是传递过来的属性数据
      this.floorData0 = data[0];
      this.floorData1 = data[1];
      this.floorData2 = data[2];
    },
  }
}
</script>
<style scoped>
  .floor-title {
    text-align: center;
    font-size: 14px;
    height: 1.8rem;
    line-height: 1.8rem;
  }
  .floor-anomaly {
    background-color: #fff;
    display: flex;
    border-bottom: 1px solid #ddd;
  }
  .floor-anomaly > div {
    width: 10rem;
  }
  .floor-one {
    border-right: 1px solid #ddd;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
  }
  .floor-two {
    border-bottom: 1px solid #ddd;
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
  }
  .floor-rule {
    display: flex;
    flex-wrap: wrap;
    background-color: #fff;
  }
  .floor-rule > div {
    width: 10rem;
    border-bottom: 1px solid #ddd;
  }
  .floor-rule > div:nth-child(odd){
    box-sizing: border-box;
    -webkit-box-sizing: border-box;
    border-right: 1px solid #ddd;
  }
</style>
